<?php
function seitcm_check_student_reg_before($studentid,$datetime)
{
	global $wpdb;
	return $wpdb->get_var($wpdb->prepare('SELECT COUNT(id) FROM '. SEITCM_TABLE_REGISTER .' WHERE studentid = %d AND time < %d',$studentid,$datetime));
}
/**
 * 
 * @param array $studentlist
 * @param integer $classid
 * @return boolean
 */
function seitcm_reg_list_student($studentlist, $classid)
{
	global $wpdb;
	$wpdb->query('start transaction');
	foreach ($studentlist as $studentid)
	{
		if(!($wpdb->query($wpdb->prepare('INSERT INTO '. SEITCM_TABLE_REGISTER .' (studentid,classid,discounts,collectedfee,time,note) VALUES (%d,%d,%d,%d,%s,%s)',$studentid,$classid,0,0,seitcm_get_current_sql_datetime(),''))))
		{
			$wpdb->query('rollback');
			return false;
		}
		else 
		{
			$learningstatus = get_user_meta($studentid, 'learningstatus');
			if($learningstatus == 1 || $learningstatus == 4)
				update_user_meta($studentid, 'learningstatus', 2);
			else if($learningstatus == 3)
				update_user_meta($studentid, 'learningstatus', 4);
			update_user_meta($studentid, 'currentclass', $classid);
		}
	}
	$wpdb->query('commit');
	return true;
}
?>